package com.sailfish.springbootdemo.dao.db6;

import com.sailfish.springbootdemo.common.DB1TableName;
import com.sailfish.springbootdemo.common.DB6TableName;
import com.sailfish.springbootdemo.pojo.db6.CompanyInfo;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface CompanyInfoDao {

    /**
     *
     * @param companyId
     * @return
     */
    @Results(id = "companyInfoResultMap", value = {
            @Result(column = "company_info_id", property = "companyInfoId", jdbcType = JdbcType.INTEGER),
            @Result(column = "result", property = "result", jdbcType = JdbcType.VARCHAR),
            @Result(column = "company_id", property = "companyId", jdbcType = JdbcType.INTEGER),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "is_modify", property = "isModify", jdbcType = JdbcType.INTEGER),
            @Result(column = "result_first", property = "resultFirst", jdbcType = JdbcType.VARCHAR),
    })
    @Select("select * from " + DB6TableName.COMPANY_INFO + " where company_id = #{companyId}")
    List<CompanyInfo> getCompanyInfoByCompanyId(@Param("companyId")Integer companyId);

    @Insert("insert into " + DB6TableName.COMPANY_INFO + " (result,company_id,update_time,is_modify,result_first) values (#{companyInfo.result},#{companyInfo.companyId},#{companyInfo.updateTime},#{companyInfo.isModify},#{companyInfo.resultFirst})")
    Integer addCompanyInfo_23(@Param("companyInfo") CompanyInfo companyInfo);

    @Insert("insert into " + DB6TableName.COMPANY_INFO + " (result,company_id,update_time,is_modify) values (#{companyInfo.result},#{companyInfo.companyId},#{companyInfo.updateTime},#{companyInfo.isModify})")
    Integer addCompanyInfo_Not_23(@Param("companyInfo") CompanyInfo companyInfo);


    @Update("<script>" +
            "update " + DB6TableName.COMPANY_INFO +
            "<set>" +
            "<if test='companyInfo.result != null and companyInfo.result != \"\" '>" +
            " result = #{companyInfo.result}," +
            "</if>" +
            "<if test='companyInfo.resultFirst != null and companyInfo.resultFirst != \"\" '>" +
            " result_first = #{companyInfo.resultFirst}," +
            "</if>" +
            "<if test='companyInfo.updateTime != null '>" +
            " update_time = #{companyInfo.updateTime}," +
            "</if>" +
            "<if test='companyInfo.isModify != null and companyInfo.isModify != \"\" '>" +
            " is_modify = #{companyInfo.isModify}," +
            "</if>" +
            "</set>" +
            " where company_id = #{companyInfo.companyId}" +
            "</script>")
    Integer updateCompanyInfo(@Param("companyInfo") CompanyInfo companyInfo);
}
